﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Collections;
using System.Windows.Forms;

namespace sales.forms
{
    public partial class orderError : common.forms.baseDialogForm
    {
        public orderError()
        {
            try
            {
                InitializeComponent();
            }
            catch(Exception er)
            {
                this.ShowError(er);
            }
        }

        public void Restart()
        {
            dataTab.TabPages.Clear();
        }
        public void SetDataERROR(OrderErrors errorTbl)
        {
            dataErrorSource.DataSource = errorTbl;
            dataErrorGrid.myAutoFitColumn = dataErrorMsgColumn.Name;
            dataErrorGrid.AutoArrange();
            if (errorTbl.Count > 0) dataTab.TabPages.Add(errorDataPg);
        }
        public void SetDataSALECODE(inventory.SaleCodeInfo info)
        {
            saleCodeSumGrid.Init(info, info.GetErrorFiter());
            string[] columnNames = new string[] 
            { 
                inventory.Controls.gridSaleCodeSum.ColumnNames.code.ToString(),
                inventory.Controls.gridSaleCodeSum.ColumnNames.itemCode.ToString(),
                inventory.Controls.gridSaleCodeSum.ColumnNames.itemName.ToString(),
                inventory.Controls.gridSaleCodeSum.ColumnNames.itemUnit.ToString(),
                inventory.Controls.gridSaleCodeSum.ColumnNames.qtySale.ToString(),
                inventory.Controls.gridSaleCodeSum.ColumnNames.qtySaleReturn.ToString(),
                inventory.Controls.gridSaleCodeSum.ColumnNames.qtyOut.ToString(),
                inventory.Controls.gridSaleCodeSum.ColumnNames.qtyOutReturn.ToString(),
                inventory.Controls.gridSaleCodeSum.ColumnNames.qtyRemain.ToString()
            };
            saleCodeSumGrid.SetColumnVisible(columnNames);
            if (saleCodeSumGrid.RowCount > 0) dataTab.TabPages.Add(saleCodePg);
        }

        public override void Refresh()
        {
            base.Refresh();
            dataTab_SelectedIndexChanged(null, null);
        }
        private void dataTab_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (dataTab.SelectedTab == errorDataPg)
                {
                    dataErrorGrid.AutoArrange();
                    return;
                }
                if (dataTab.SelectedTab == saleCodePg )
                {
                    saleCodeSumGrid.AutoArrange();
                    return;
                }
            }
            catch (Exception er)
            {
                this.ShowError(er);
            }
        }
    }
}
